package com.tshopping.service.impl;

import com.tshopping.bean.Level;
import com.tshopping.dao.LevelDao;
import com.tshopping.service.LevelService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

/**
 * @name: LevelServiceImpl
 * @description: 类型业务层类
 * @author: Jackeys
 * @date: 2021-01-08 08:33
 */
@Service(value = "levelService")
@Transactional
public class LevelServiceImpl implements LevelService {

    @Autowired
    private LevelDao levelDao;
    @Override
    /**
     * @description 处理添加分类
     * @Param: name
     * @Param: parent
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 08:36
     */
    public ResponseData addLevel(String name, int parent) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("flag",levelDao.insertLevel(name,parent));
        return responseData;
    }

    @Override
    /**
     * @description 处理查询特定类别
     * @Param: parent
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 08:37
     */
    public ResponseData selectLevels(int parent) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("levelList",levelDao.selectLevelByParent(parent));
        return responseData;
    }

    @Override
    /**
     * @description 处理修改类别名称
     * @Param: name
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 08:39
     */
    public ResponseData updateLevel(String name,int parent, int id) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("flag",levelDao.updateNameById(name,parent,id));
        return responseData;
    }

    @Override
    /**
     * @description 处理删除类别
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 08:39
     */
    public ResponseData deleteLevel(int id) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("flag", levelDao.deleteLevelById(id));
        return responseData;
    }

    @Override
    /**
     * @description 处理查询所有类别
     * @Param:
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-08 08:40
     */
    public ResponseData selectAllLevels() {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("levelList",levelDao.selectAllLevels());
        return responseData;
    }

    @Override
    /**
     * @description 处理查询类别
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-25 09:50
     */
    public ResponseData selectLevel(int id) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("level",levelDao.selectLevelByLevelId(id));
        return responseData;
    }
}
